package com.mall.business.controller;


import java.util.Arrays;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import cn.hutool.extra.servlet.ServletUtil;
import com.mall.common.annotation.Log;
import com.mall.common.core.controller.BaseController;
import com.mall.common.core.domain.AjaxResult;
import com.mall.common.enums.BusinessType;
import com.mall.common.utils.SecurityUtils;
import com.mall.common.utils.ServletUtils;
import com.mall.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.mall.business.domain.TOrderPj;
import com.mall.business.service.ITOrderPjService;
import com.mall.common.core.page.TableDataInfo;

/**
 * 订单评价Controller
 *
 * @author ruoyi
 * @date 2025-03-30
 */
@RestController
@RequestMapping("/business/pj" )
public class TOrderPjController extends BaseController {
    @Autowired
    private ITOrderPjService tOrderPjService;

/**
 * 查询订单评价列表
 */
//@RequiresPermissions("business:pj:list")
@GetMapping("/list" )
    public TableDataInfo list(TOrderPj tOrderPj) {
        startPage();
        List<TOrderPj> list = tOrderPjService.selectTOrderPjList(tOrderPj);
        return getDataTable(list);
    }

    /**
     * 导出订单评价列表
     */
    //@RequiresPermissions("business:pj:export")
    @Log(title = "订单评价" , businessType = BusinessType.EXPORT)
    @PostMapping("/export" )
    public void export(HttpServletResponse response, TOrderPj tOrderPj) {
        List<TOrderPj> list = tOrderPjService.selectTOrderPjList(tOrderPj);
        ExcelUtil<TOrderPj> util = new ExcelUtil<TOrderPj>(TOrderPj. class);
        util.exportExcel(response, list, "订单评价数据" );
    }

    /**
     * 获取订单评价详细信息
     */
    //@RequiresPermissions("business:pj:query")
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) String id) {
        return AjaxResult.success(tOrderPjService.selectTOrderPjById(id));
    }

    /**
     * 新增订单评价
     */
    //@RequiresPermissions("business:pj:add")
    @Log(title = "订单评价" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated   @RequestBody TOrderPj tOrderPj) {
        tOrderPj.setUserId(SecurityUtils.getUserIdStr());
        return toAjax(tOrderPjService.save(tOrderPj));
    }

    /**
     * 修改订单评价
     */
    //@RequiresPermissions("business:pj:edit")
    @Log(title = "订单评价" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated  @RequestBody TOrderPj tOrderPj) {
        return toAjax(tOrderPjService.updateById(tOrderPj));
    }

    /**
     * 删除订单评价
     */
    //@RequiresPermissions("business:pj:remove")
    @Log(title = "订单评价" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(tOrderPjService.removeByIds(Arrays.asList(ids)));
    }
}
